<?php
namespace app\admin\model;
use think\Model;
use think\Db;
/**
 * Created by PhpStorm.
 * User: 空房间
 * Date: 2018/2/24
 * Time: 15:48
 */
class Moduleinfoset extends Model
{
    public function moduleInfoSet_list(){
        return db( 'module_info_set' )
            ->alias('m')
            ->field('u.username,m.id,m.form_title,m.module_type,m.create_time')
            ->join('__USER__ u','m.uid = u.id')
            ->order('m.id desc')
            ->paginate( 20 );
    }
    /**
     * 数据添加
     * @param array $data
     * @return bool
     */
    public function moduleInfoSet_add($data=array())
    {
        if($data)
        {

            Db::startTrans();
            try{
                $result =  Db::table('mzzs_module_info_set')->data($data)->insert();
                // 提交事务
                Db::commit();
                return true;
            } catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                return false;
            }
        }else{
            return false;
        }
    }
    /**
     * 根据ID查询数据
     */
    public function getInfoById($condition = array()){
        $where = array();
        if($condition)$where =  array_merge($condition,$where);
        $info = db('module_info_set')
            ->where($where)
            ->find();
        return $info;
    }
    /**
     * 更新数据
     */
    public function update_info($condition='',$data)
    {
        if($data)
        {

            Db::startTrans();
            try{
                unset($data['id']);
                $result =  Db::table('mzzs_module_info_set')->where('id',$condition)->update($data);
                // 提交事务
                Db::commit();
                return true;
            } catch (\Exception $e) {
                // 回滚事务
                Db::rollback();
                return false;
            }
        }else{
            return false;
        }
    }
    /**
     * 删除数据
     */
    public function del_info($condition=''){
        $result = Db::table('mzzs_module_info_set')->where(['id'=>$condition])->delete();
        return  $result ? true:false;
    }
    /**
     * 批量删除
     */
    public function all_del_info($condition=array()){
        $result = Db::table('mzzs_module_info_set')->where('id','in',$condition)->delete();
        return  $result ? true:false;
    }
}